/* 
 *      SymbolizedToken.java
 *
 *      Copyright 2008 Pablo Nicolas Diaz Bilotto <pablonicolas.diaz@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
package lexer.token;

import lexer.EntryType;
import symbolStorageService.ISymEntry;


/**
 * The Class SymbolizedToken.
 */
public class SymbolizedToken extends Token {

	/** The thing. */
	private Object thing;

	/** The Symbol entry. */
	private ISymEntry SymbolEntry;

	/**
	 * Instantiates a new symbolized token.
	 * 
	 * @param thing the thing
	 * @param symEntry the sym entry
	 */
	public SymbolizedToken(Object thing, ISymEntry symEntry) {
		super(symEntry.getLineNumber(), symEntry.getKind());
		this.setSymbolEntry(symEntry);
		this.setThing(thing);
	}

	/**
	 * Gets the symbol entry.
	 * 
	 * @return the symbol entry
	 */
	public ISymEntry getSymbolEntry() {
		return SymbolEntry;
	}

	/**
	 * Gets the thing.
	 * 
	 * @return the thing
	 */
	private Object getThing() {
		return thing;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see lexer.token.BaseToken#getType()
	 */
	public EntryType getType() {
		return getSymbolEntry().getType();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see lexer.token.Token#getValue()
	 */
	@Override
	public Object getValue() {
		return getThing();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see lexer.token.BaseToken#hasValidType()
	 */
	public boolean hasValidType() {
		return EntryType.isValuedType(getType());
	}

	/**
	 * Sets the symbol entry.
	 * 
	 * @param symbolEntry the new symbol entry
	 */
	private void setSymbolEntry(ISymEntry symbolEntry) {
		SymbolEntry = symbolEntry;
	}

	/**
	 * Sets the thing.
	 * 
	 * @param thing the new thing
	 */
	private void setThing(Object thing) {
		this.thing = thing;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see lexer.token.BaseToken#setValue(java.lang.Object)
	 */
	public void setValue(Object literal) {
		setThing(literal);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see lexer.token.Token#token_to_yacc()
	 */
	@Override
	public int token_to_yacc() {
		return SymbolEntry.getKind().retValue();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see lexer.token.Token#toString()
	 */
	@Override
	public String toString() {
		return super.toString() + " Value: " + this.thing.toString();
	}
}
